package com.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @classDesc: 功能描述：(读取springboot配置文件，测试用。springboot启动后，可用@value代替)
 * @author: 王杰
 * @createTime: 2017年11月12日  12:10
 * @version: V1.0
 */
public class ProBootUtil {
    private ProBootUtil() {
    }

    public static String getValue(String key){
        String readPath = "/application.properties";
        String value = "";
//        InputStream in = ProBootUtil.class.getClassLoader().getResourceAsStream(readPath);
        InputStream in = ProBootUtil.class.getResourceAsStream(readPath);
        Properties pro = new Properties();
        try {
            pro.load(in);
            in.close();
        }catch (FileNotFoundException ignored){
            System.out.println("ProBootUtil找不到这个文件："+ readPath);
        } catch (IOException e) {
            System.out.println("ProBootUtil读取文件错误："+ readPath);
            e.printStackTrace();
        }
        if(pro.containsKey(key)){
            value = pro.getProperty(key);
        }
        return value;
    }

}
